class Solution
{
public:
    int giveGem(vector<int> &gem, vector<vector<int>> &operations)
    {
        for (auto &op : operations)
        {
            int change = gem[op[0]] / 2;
            gem[op[0]] -= change;
            gem[op[1]] += change;
        }
        auto [minIt, maxIt] = minmax_element(gem.begin(), gem.end());
        return *maxIt - *minIt;
    }
};